home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / subdDagMenuProc.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.6 KB  |  273 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Dec 3, 1999
  22. //  Author:         ms
  23. //
  24. //  Description:
  25. //      This script describes the contents of the context sensitive menus
  26. //       for the subdivision surfaces, originally all in dagMenuProc.mel
  27. //
  28. //  Input Arguments:
  29. //      None.
  30. //
  31. //  Return Value:
  32. //      None.
  33. //
  34.  
  35. global proc subdDagMenuProc( int $action, string $item, string $maskList[] )
  36. {
  37.     string $subdivSelectionPositions[3];
  38.     $subdivSelectionPositions[0] = "W";
  39.     $subdivSelectionPositions[1] = "N";
  40.     $subdivSelectionPositions[2] = "S";
  41.     $subdivSelectionPositions[3] = "E";
  42.  
  43.     int $whichMode = `subdiv -q -proxyMode $item`;
  44.     string $componentsOnThisNode = $item;
  45.  
  46.     if( 1 == $whichMode ) {
  47.         // We're in polygon mode -- update the values of
  48.         // $componentsOnThisNode and $maskList so the marking menu
  49.         // commands below will operate on the poly proxy and not the
  50.         // subd.  (The subd components aren't selectable or drawn in
  51.         // proxy mode.)
  52.         //
  53.         // This way, users will use the subd marking menus to turn on
  54.         // "faces," for example, but they'll really be turning on the
  55.         // faces on the poly proxy, not the subd.
  56.         //
  57.         $componentsOnThisNode = subdFindProxyModePolygon( $item );
  58.  
  59.         if( size( $componentsOnThisNode ) > 0 ) {
  60.             string $tmpMask[] = `objectSelectMasks( $componentsOnThisNode )`;
  61.             
  62.             // The poly selection masks aren't in the same order as those
  63.             // for the subs.  Remap...
  64.             //
  65.             $maskList[0] = $tmpMask[1]; // vertices
  66.             $maskList[1] = $tmpMask[0]; // edges
  67.             $maskList[2] = $tmpMask[2]; // faces
  68.             $maskList[3] = $tmpMask[3]; // maps/UVs
  69.         } 
  70.         // Just protecting ourselves in case we think we're in
  71.         // proxy mode, but we can't find the proxy.
  72.         // 
  73.         else {
  74.             $componentsOnThisNode = $item;
  75.             warning( "Cannot find proxy for subdivision surface in proxy mode." );
  76.         }
  77.     }
  78.  
  79.     // create three selection items for the different component types
  80.     //
  81.     string $uiName;
  82.     for ($i = 0; $i < size($maskList); $i++) {
  83.         switch ($maskList[$i]) {
  84.             case "subdivMeshPoint":
  85.             case "vertex":
  86.                 $uiName = "Vertex";
  87.                 break;
  88.             case "subdivMeshEdge":
  89.             case "edge":
  90.                 $uiName = "Edge";
  91.                 break;
  92.             case "subdivMeshFace":
  93.             case "facet":
  94.                 $uiName = "Face";
  95.                 break;
  96.             case "subdivMeshUV":
  97.             case "puv":
  98.                 $uiName = "UV";
  99.                 break;
  100.             default:
  101.                 $uiName = `interToUI $maskList[$i]`;
  102.                 break;
  103.         }
  104.         menuItem -l $uiName
  105.             -ecr false
  106.             -c ( "doMenuComponentSelection(\"" +
  107.                  $componentsOnThisNode + "\", \"" +  $maskList[$i] + "\")")
  108.             -rp $subdivSelectionPositions[$i];
  109.     }
  110.  
  111.     // If there are two subdiv shapes underneath the
  112.     // same transform (for instance, if the user picks a deformed 
  113.     // subd, and invokes Deform->Show Intermediate Objects)
  114.     // the getAttr command below of the form
  115.     // 
  116.     //         getAttr ( $item + ".displayFilter" );
  117.     // 
  118.     // will return two values in an int array, instead of a simple
  119.     // int: one value for each of the subdiv shapes under the
  120.     // transform $item.
  121.     // 
  122.     // Note that a simliar "setAttr"  command
  123.     // 
  124.     //         setAttr ( $item + ".displayFilter" ) 0 0;
  125.     // 
  126.     // would require two numeric values on the command line, for the
  127.     // same reason.  Since MEL doesn't allow assigning an int to an
  128.     // int[] (or vice versa) we have to be careful of how we form the
  129.     // commands for these objects.
  130.     // 
  131.     //         $children[] : all the leaf-level subdiv children of $item
  132.     //         $subdShapes : the members of $children that are *not* 
  133.     //                      intermediate objects.  For convenience
  134.     //                      when passing to the setSubdivDisplayLevelAndFilter
  135.     //                      proc later on, $subdShapes is the string 
  136.     //                      representation of an array.
  137.     //         $numSubdShapes: the number of elements in the string "array"
  138.     //                      $subdShapes.
  139.     // 
  140.     string $children[] = `ls -dag -leaf -type subdiv $item`;
  141.     string $subdShapes = "{ ";
  142.     string $firstSubdShape = "";
  143.     int    $numSubdShapes = 0, $maybeProxy = 0;
  144.     string $child;
  145.  
  146.     string $mChildren[] = `ls -dag -leaf -type mesh $item`;
  147.     for( $child in $mChildren ) {
  148.         if ( !`getAttr ($child+".io")` &&
  149.               `getAttr ($child+".visibility")`) {
  150.             $maybeProxy = 1;
  151.         }
  152.     }
  153.     // For all leaf-level subdiv shapes under $item
  154.     //
  155.     for( $child in $children ) {
  156.         // Weed out the intermediate objects
  157.         //
  158.         if( !`getAttr ($child+".io")` ) {
  159.             // Keep track of the first one for a command later on.
  160.             //
  161.             if( $numSubdShapes == 0 ) {
  162.                 $firstSubdShape = $child;
  163.             } 
  164.             // Comma separate members of the string "array"
  165.             //
  166.             else {
  167.                 $subdShapes += ", ";
  168.             }
  169.  
  170.             $subdShapes += ( "\"" + $child + "\"" );
  171.             $numSubdShapes++;
  172.         }
  173.     }
  174.     $subdShapes += " } ";
  175.  
  176.     menuItem -l "Finer"
  177.         -annotation "Set Component Display: Finer"
  178.         -echoCommand true
  179.         -c ( "setSubdivDisplayLevelAndFilter " + $subdShapes + "\"+1\" 0" )
  180.         -rp "NW"
  181.         setSubdivComponentDisplayFiner;
  182.  
  183.     menuItem -l "Coarser"
  184.         -annotation "Set Component Display: Coarser"
  185.         -echoCommand true
  186.          -c ( "setSubdivDisplayLevelAndFilter " + $subdShapes + "\"-1\" 0" )
  187.         -rp "SW"
  188.         setSubdivComponentDisplayCoarser;
  189.  
  190.     // The "refine" and "filter" commands below use "setAttr" commands
  191.     // that need one numeric value per valid subdiv shape under the
  192.     // $item transform.  Build up a string with desired value repeated
  193.     // an appropriate number of times.
  194.     // 
  195.     string $filterString = "";
  196.     for( $i = 0; $i < $numSubdShapes; $i++ ) {
  197.         $filterString += "0 ";
  198.     }
  199.  
  200.     // In the case of multiple subdiv shapes, they could conceivably
  201.     // have different "displayFilter" attribute values.  To build up
  202.     // the marking menu commands, we'll just go with the attribute
  203.     // state of the first valid subdiv shape we found.
  204.     //
  205.  
  206.     int $whichMode = `subdiv -q -proxyMode $firstSubdShape`;
  207.     if( 1 == $whichMode ) {
  208.         // We are in polygon mode.  Create a menu item to switch back
  209.         // to standard editing mode.
  210.         menuItem -l "Standard"
  211.             -annotation ("Edit subdiv components in the standard mode")
  212.             -echoCommand true
  213.             -c ("subdGivenIntoHierMode " + $item + "")
  214.             -rp "SE"
  215.             setSubdivHierMode;
  216.  
  217.     } else if( 0 == $whichMode ) {
  218.         menuItem -l "Polygon"
  219.             -annotation ("Edit polygon proxy object")
  220.             -echoCommand true
  221.             -c ("subdGivenIntoPolyMode " + $item + " 1 0 0 0")
  222.             -rp "SE"
  223.             setSubdivPolyMode;
  224.     } else if( 2 == $whichMode ) {
  225.         // The Polygon menu item is disabled in this case to
  226.         // indicate that this subdivision surface
  227.         // is not in Polygon Proxy mode, but could be
  228.         // put into Polygon Proxy mode if its construction
  229.         // history was deleted.
  230.  
  231.         string $label;
  232.         string $annotation;
  233.         if ($maybeProxy) {
  234.             // If there is a non-intermediate, visible meshShape
  235.             // thats a sibling of this subdShape, then thats
  236.             // a result of the user binding a skeleton to a
  237.             // a subd in the proxy mode. (which is discouraged,
  238.             // incorrect, but cannot be prevented)
  239.             //
  240.             // If such a mesh is in the history of this subd, then
  241.             // we can be sure that we are in the polygon proxy mode.
  242.             // If so, we should set the label to "Standard"( to which
  243.             // they can switch by deleting history)
  244.             //
  245.             string $inNodes[] = `listHistory -il 2 $firstSubdShape`;
  246.             int $found = 0;
  247.             for ($node in $inNodes) {
  248.                 for ($mesh in $mChildren) {
  249.                     if ($node == $mesh) {
  250.                         $label = "Standard";
  251.                         $annotation = "Edit subdiv components in the standard mode";
  252.                         $found = 1;
  253.                         break;
  254.                     }
  255.                 }
  256.                 if ($found) break;
  257.             }
  258.             if (!$found) {
  259.                 $label = "Polygon";
  260.                 $annotation = "Edit polygon proxy object";
  261.             }
  262.         } else $label = "Polygon";
  263.  
  264.         menuItem -l $label
  265.             -annotation $annotation
  266.             -en false
  267.             -echoCommand true
  268.             -c ("subdGivenIntoPolyMode " + $item + " 1 0 0 0")
  269.             -rp "SE"
  270.             setSubdivPolyMode;
  271.     }
  272. }
  273.